import Vue from 'vue'
import Router from 'vue-router'
import Login from './views/Login.vue'
import Home from './views/Home.vue'
import main from './views/main.vue'
import record from "./views/record";
import userInfo from "./views/userInfo";
import provinceBloodVolume from "./views/provinceBloodVolume";
import bloodTypeBloodVolume from "./views/bloodTypeBloodVolume";
import provinceInfo from "./views/provinceInfo";
import bloodTypeInfo from "./views/bloodTypeInfo";
import adminSelfInfo from "./views/adminSelfInfo";
import userRegister from "./views/userRegister";
import userHome from "./views/userHome";
import recordEntry from "./views/recordEntry";
import userSelfInfo from "./views/userSelfInfo";
import userTotalBloodVolume from "./views/userTotalBloodVolume";
import recordManage from "./views/recordManage";
import suyuan from "./views/suyuan";
import bloodBankInfo from "./views/bloodBankInfo";
import planterHome from "./views/planterHome";
import planterInfo from "./views/planterInfo";
import processHome from "./views/processHome";
import processInfo from "./views/processInfo";
import logisticsInfo from "./views/logisticsInfo";
import logisticsHome from "./views/logisticsHome";
import saleHome from "./views/saleHome";
import saleInfo from "./views/saleInfo";


Vue.use(Router)

const router = new Router({
  routes: [
	  {path: '/',
	    redirect: '/login'
	  },
    {path: '/login',
      component: Login
    },
    {path: '/userRegister',
      component: userRegister
    },


    //种植
    { path: '/planterHome',
      component: planterHome,
      redirect: '/planterHome',
      children: [
        {
          path: '/planterHome',
          name: '首页',
          component: main
        },

        {
          path: '/planterInfo',
          name: '种植信息',
          component: planterInfo
        }
      ]
    },


    //加工
    { path: '/processHome',
      component: processHome,
      redirect: '/processHome',
      children: [
        {
          path: '/processHome',
          name: '首页',
          component: main
        },

        {
          path: '/processInfo',
          name: '加工信息',
          component: processInfo
        }
      ]
    },







    //储运
    { path: '/logisticsHome',
      component: logisticsHome,
      redirect: '/logisticsHome',
      children: [
        {
          path: '/logisticsHome',
          name: '首页',
          component: main
        },

        {
          path: '/logisticsInfo',
          name: '储运信息',
          component: logisticsInfo
        }
      ]
    },



    //经销
    { path: '/saleHome',
      component: saleHome,
      redirect: '/saleHome',
      children: [
        {
          path: '/saleHome',
          name: '首页',
          component: main
        },

        {
          path: '/saleInfo',
          name: '储运信息',
          component: saleInfo
        }
      ]
    },


    { path: '/userHome',
      component: userHome,
      redirect: '/userHome',
      children: [
        {
          path: '/userHome',
          name: '首页',
          component: main
        },
        {
          path: '/suyuan',
          name: '信息追溯',
          component: suyuan
        },

        {
          path: '/userSelfInfo',
          name: '个人信息',
          component: userSelfInfo
        }
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
	console.log('进入')
  if (to.path === '/login') {
    // 是登录页面，直接进入到 要访问的登录页面
    return next()
  }
  if (to.path === '/userRegister') {
    // 是注册页面，直接进入到 要访问的页面
    return next()
  }

  // 不是登录页面
  const token = localStorage.getItem('token')
  console.log("token",token)
  if (token) {
	  console.log('登陆过')
    // 登录过：
    next()
  }else {
	  console.log('未登录过')
    // 没有登录过
    next('/login')
  }
})



export default router
